<?
	//could perhaps build this into the 404 directly.. ponders.. 
	
require_once("fta.201003310000/fta.php");
fta_registerModules(
	array(
	"cms.201003310000/config/cmsConfig",//we will deprecate the old cms config soon..
	"site/components/MAISlideshow",
));	
	
	//this builds pages for the page builder doohickey..
	
	$authInfo = setupPublicUser();
	
	//first get the cmskvcid.. and load it..
	
	$id = extractStringWithKeyFromArray('id', $_GET, null);
	
	if (is_null($id) || strlen($id) != 8 ) {
		header("http/1.0 500 Internal Server Error", true);
		die("No page id specified");	
	}
	
	$key = 'pb_generated_'. $id;

	// now try and load it ..
	
	$content = null;
	if (CMS_APC_ENABLED && $hasAPC) {
		$success = false;
		$content = apc_fetch( $key, $success );	
		if (!$success)
			$content = null;
	}
	
	if (is_null($content)) {
		
		//$cmsPageBuilder = new CmsPageBuilder();
		$cmsPageBuilder = new $CMS_PAGEBUILDER_CLASS;
		$loaded = $cmsPageBuilder->load($id, $authInfo, $db );
		
		
		if ( !$loaded ) {
			header("http/1.0 500 Internal Server Error", true);
			die("Could not load page builder");			
		} else {
			//echo "page builder = <pre>";print_r($cmsPageBuilder);echo "</pre>";
			$content = $cmsPageBuilder->generateHTML($db);
			if (CMS_APC_ENABLED && $hasAPC)
				apc_add($key,$content, CMS_APC_TTL);// we add to the cache here.. and expect that something else will clean up??? no this week
			
		}
		
	}
	
	echo $content;
